linux 监控 句柄

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 3955

2019/03/31 13:27


示例:点击 -> 性能监控

/proc/sys/fs/file-nr  每列分别代表:

已分配文件句柄的数目     已使用文件句柄的数目      文件句柄的最大数目    

[root@wangzi go]# cat /proc/sys/fs/file-nr
1280	0	98406

 

python监控代码:

#!/usr/bin/env python
# coding=utf-8
# author: brownwang
# mail: 277215243@qq.com
# datetime:2019/3/31 1:03 PM
# web: https://www.bthlt.com

def fd_use():
    free=0
    used=0
    total=0
    with open('/proc/sys/fs/file-nr','r') as file:
        for line in file.readlines():
            used=int(line.split()[0])
            total=int(line.split()[2])
    free=total-used
    insert_sql="""insert into `monitor_fd_use` (`used`,`free`,`flow_time`) values ({0},{1},'{2}')""".format(used,free,now_zero)
    cursorUpdate(insert_sql,[])

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1